package com.yunyi.web.controller.freezing;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yunyi.common.core.domain.AjaxResult;
import com.yunyi.system.service.EmrCaseSlideService;
import com.yunyi.system.service.SysOfficeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 3.2 冰冻管理
 *  3.2.1 待分诊预约
 */
@RestController
@RequestMapping("/freezing/maa")
@Api(tags = "测试冰冻管理")
public class FreezingManagerController {

    @Resource
    private SysOfficeService service;

    @Resource
    private EmrCaseSlideService ecsService;

    /**
     * 获取申请医院信息
     * @return
     */
    @ApiOperation(value = "获取申请医院")
    @GetMapping("/getHospital")
    public AjaxResult getApplayForHospital(){
        return service.getApplayForHospital();
    }

    /**
     * 根据申请医院获取病例信息
     * @param hospital  申请医院
     * @param pageNum   默认值：1
     * @param pageSize  默认值：19
     * @return
     */
    @ApiOperation(value = "根据申请医院获取病例信息")
    @GetMapping("getCase")
    public AjaxResult getCaseByHospital(Integer status,String hospital,
                                        @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize",defaultValue = "19") Integer pageSize) {
        return ecsService.getCaseByHospital(status,hospital,pageNum,pageSize);
    }

    @ApiOperation(value = "获取切片信息")
    @GetMapping("getSlides/{caseNo}")
    public AjaxResult getSlides(@PathVariable String caseNo){
        return ecsService.getSlides(caseNo);
    }

    @ApiOperation("批量分配")
    @PutMapping("/allotCaseSlide")
    public AjaxResult allotCaseSlide(@RequestBody List<String> ids) {
        return ecsService.allotCaseSlide(ids);
    }

    @PutMapping("returnSite/{id}")
    public AjaxResult returnSite(@PathVariable String id){
        UpdateWrapper updateWrapper = new UpdateWrapper<>()
                .set("apmstatus",1)
                .set("update_date",new Date())
                .eq("id",id);
        return ecsService.update(updateWrapper) ? AjaxResult.success("退回成功！") : AjaxResult.error("退回失败！");
    }

    @PutMapping("revocation/{id}")
    public AjaxResult revocation(@PathVariable String id, String reason) {
        return ecsService.revocation(id, reason);
    }
}
